import request from '@/utils/request'

// 获取权限列表
export function getPermissionList(params) {
  return request({
    url: '/permissions',
    method: 'get',
    params
  })
}

// 获取权限详情
export function getPermissionDetail(permissionId) {
  return request({
    url: `/permissions/${permissionId}`,
    method: 'get'
  })
}

// 新增权限
export function addPermission(data) {
  return request({
    url: '/permissions',
    method: 'post',
    data
  })
}

// 编辑权限
export function updatePermission(data) {
  return request({
    url: `/permissions/${data.id}`,
    method: 'put',
    data
  })
}

// 删除权限
export function deletePermission(permissionId) {
  return request({
    url: `/permissions/${permissionId}`,
    method: 'delete'
  })
}

// 启用权限
export function enablePermission(permissionId) {
  return request({
    url: `/permissions/${permissionId}/enable`,
    method: 'put'
  })
}

// 禁用权限
export function disablePermission(permissionId) {
  return request({
    url: `/permissions/${permissionId}/disable`,
    method: 'put'
  })
}

// 获取全部权限（避免分页限制，默认拉取足够大的数量）
export function getAllPermissions(params = {}) {
  const merged = { page: 1, pageSize: 1000, ...params }
  return request({
    url: '/permissions',
    method: 'get',
    params: merged
  })
}